package com.hc.sys;

import javax.servlet.http.HttpServletResponse;

import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

@ControllerAdvice
public class GlobalExceptionHandler {

	/**
	 * 非法参数
	 * @param e
	 * @param response
	 * @return
	 */
	@ExceptionHandler
	@ResponseBody
	public ResponseMsg illegalArgumentException(IllegalArgumentException e, HttpServletResponse response) {
		ResponseMsg rmsg = new ResponseMsg();
		rmsg.fail(e.getLocalizedMessage());
		return rmsg;
	}
	
	/**
	 * 空指针异常
	 * @param e
	 * @param response
	 * @return
	 */
	@ExceptionHandler
	@ResponseBody
	public ResponseMsg nullPointerException(NullPointerException e, HttpServletResponse response) {
		ResponseMsg rmsg = new ResponseMsg();
		rmsg.fail(e.getLocalizedMessage());
		return rmsg;
	}
}
